/*
*  Copyright (c) 2006-2020, Chukie
*
*  SPDX-License-Identifier: Apache-2.0
*
*  @file     : cellular_comm.c
*
*  @brief    :
*  Website   : https://gitee.com/open-embedded
*
*
*  Change Logs:
*  Date           Author          Notes
*  2020-06-23     zhaocj       The first version
*/
/* Includes -----------------------------------------------------------------*/
#include "cellular.h"
#include "cellular_comm.h"
#define DBG_TAG     "CELL-COMM"
#define DBG_LVL DBG_LOG
#include "cellular_log.h"
/* Private typedef ----------------------------------------------------------*/
/* Private define -----------------------------------------------------------*/
/* Private variables --------------------------------------------------------*/
const char *reg_state_info[REGISTER_STATE_STATE_MAX + 1] =
{
    "Not registered, but MT is not searching.",
    "Registered, home network.",
    "Not registered, but MT is currently trying to attach or searching.",
    "Not registered, Registration denied.",
    "Not registered, Unknown (e.g. out of E-UTRAN coverage).",
    "Registered, Roaming.",
    "Unknow state."
};
/* Extern variables ---------------------------------------------------------*/
/* Private function prototypes ----------------------------------------------*/


/* Public function prototypes -----------------------------------------------*/
void cellular_comm_init(cellular_device_t dev)
{
    RT_ASSERT(dev);
    cellular_hw_init();
    dev->module_info.state = cellular_read_state_from_nv();
    CLOG_NOTICE("Load module state: %d", dev->module_info.state);
    dev->dial_info.used_sim = cellular_read_used_sim_from_nv();
    CLOG_NOTICE("Load used sim index: %d", dev->dial_info.used_sim + 1);
    cellular_comm_select_sim(dev,cellular_get_used_sim_idx(dev));
}

void cellular_comm_set_module_state(cellular_device_t dev, module_state_t state)
{
    rt_base_t level = rt_hw_interrupt_disable();
    dev->module_info.state = state;
    cellular_save_state_to_nv(state);
    rt_hw_interrupt_enable(level);
}

void cellular_comm_select_sim(cellular_device_t dev,uint8_t sim_idx)
{
    rt_base_t level = rt_hw_interrupt_disable();
    cellular_hw_sim_switch(sim_idx & 0x01);
    dev->dial_info.used_sim = (sim_idx & 0x01);
    CLOG_NOTICE("SIM%d selected!", ((sim_idx & 0x01) + 1));
    cellular_save_used_sim_to_nv(sim_idx & 0x01);
    rt_hw_interrupt_enable(level);
}

int cellular_comm_exe_at_list(at_client_t atc, const struct at_cmd *at_list, size_t list_size, cellular_device_t dev, uint32_t timeout)
{
    RT_ASSERT((atc && at_list && list_size && dev));
    at_cmd_t cmd = NULL;
    int ret = CELLULAR_TIMEOUT, idx = 0;
    timeout += uptime();
    do
    {
        cmd = (at_cmd_t)&at_list[idx];
        if (!cmd->name || !cmd->at)
        {
            ret = CELLULAR_OK;
            break;
        }
        else
        {
            if (!at_exe_cmd(atc, cmd, dev))
            {
                CLOG_WARN("execute %s failed!", cmd->at);
            }
            else
            {
                idx++;
            }
            if (dev->proc_cb && dev->proc_cb(ret, dev->usr_args))
            {
                CLOG_WARN("Break by user, left %d at cmd!", list_size - idx);
                if(idx < (list_size -1)){
                    ret = CELLULAR_INPROG;
                }
                break;
            }
        }
    }
    while (time_before(uptime(), timeout) && (idx < list_size));

    return ret;
}

int cellular_comm_exe_creg_list(at_client_t atc, const struct at_cmd *at_list, size_t list_size, cellular_device_t dev, uint32_t timeout)
{
    RT_ASSERT((atc && at_list && list_size && dev));
    at_cmd_t cmd = NULL;
    int ret = CELLULAR_TIMEOUT, idx = 0;
    timeout += uptime();
    do
    {
        cmd = (at_cmd_t)&at_list[idx];
        if (!cmd->name || !cmd->at)
        {
            idx = 0;
        }
        else
        {
            if (!at_exe_cmd(atc, cmd, dev))
            {
                CLOG_WARN("execute %s failed!", cmd->at);
            }
            else
            {
                ret = CELLULAR_OK;
                break;
            }
            idx++;
            if (dev->proc_cb && dev->proc_cb(ret, dev->usr_args))
            {
                CLOG_WARN("Break by user, left %d at cmd!", list_size - idx);
                if(idx < (list_size -1)){
                    ret = CELLULAR_INPROG;
                }
                break;
            }
        }
    }
    while (time_before(uptime(), timeout) && (idx < list_size));

    return ret;
}
/**
 * @brief check sim whether ready
 *
 * @param c
 * @param resp
 * @param usr_ctx
 * @return int
 *          0: failed
 *          !0: success
 */
int cellular_comm_check_sim(at_client_t c, const char *resp, void *usr_ctx)
{
    char header[12] = {0};
    char value[12] = {0};
    RT_ASSERT(c);
    RT_ASSERT(resp);
    RT_ASSERT(usr_ctx);

    uint8_t sim_idx = cellular_get_used_sim_idx((cellular_device_t)usr_ctx);
    CLOG_DBG("used sim: %d", sim_idx);
    sim_info_t info = cellular_get_used_sim_info((cellular_device_t)usr_ctx);
    CHECK_HEADER_AND_RETURN_IF_NULL(resp, "+CPIN:");
    sscanf(resp, "%s %s", header, value);
    if (rt_strstr(value, "READY"))
    {
        info->ready = 1;
        CLOG_NOTICE("SIM[%d] ready!", sim_idx + 1);
        return RT_TRUE;
    }
    else
    {
        CLOG_WARN("SIM%d not ready!", sim_idx + 1);
        info->ready = 0;
    }
    return RT_FALSE;
}


/**
 * @brief query csq
 *
 * @param c  pointer to AT client
 * @param resp  respone buf
 * @param usr_ctx
 * @return int
 *          0: failed
 *          !0: success
 */
int cellular_comm_query_csq(at_client_t c, const char *resp, void *usr_ctx)
{
    char header[12] = {0};
    int csq = 0, bit_err = 0;
    RT_ASSERT(c);
    RT_ASSERT(resp);
    RT_ASSERT(usr_ctx);
    cell_access_info_t info = cellular_get_cell_access_info((cellular_device_t)usr_ctx);
    CHECK_HEADER_AND_RETURN_IF_NULL(resp, "+CSQ:");
    if (sscanf(resp, "%s %d,%d", header, &csq, &bit_err) >= 3)
    {
        CLOG_DBG("header: %s; csq: %d; bit_err: %d", header, csq, bit_err);
        csq = csq == 99 ? 0 : csq;
        bit_err = bit_err == 99 ? 0 : bit_err;
        info->csq = csq;
        info->biterr = bit_err;
        info->rssi = (csq * 2 - 113);
        if (csq > CELLULAR_MINI_CSQ_VALUE)
        {
            return RT_TRUE;
        }
    }

    return RT_FALSE;
}

/**
 * @brief query register state
 *
 * @param c pointer to AT client
 * @param resp
 * @param usr_ctx
 * @return int
 *          0: failed
 *          !0: success
 */
int cellular_comm_query_register(at_client_t c, const char *resp, void *usr_ctx)
{
    /**
     * +CEREG: 2,1,"802C","8257B0C",7
     *
     * OK
     *
     */
    char header[12] = {0}, lac[12] = {0}, ci[12] = {0};
    char cmd[32] = {0};
    int n = 0, stat = 0, act = 0;
    uint8_t idx = 0;
    RT_ASSERT(c);
    RT_ASSERT(resp);
    RT_ASSERT(usr_ctx);
    cell_access_info_t info = cellular_get_cell_access_info((cellular_device_t)usr_ctx);
parse_resp:
    //CLOG_DBG("resp: %s", resp);
    resp = at_skip_leading(resp, "AT+CEREG");
    //CLOG_DBG("resp: %s", resp);
    resp = at_skip_leading(resp, "AT+CGREG");
    //CLOG_DBG("resp: %s", resp);
    resp = at_skip_leading(resp, "AT+CREG");
    //CLOG_DBG("resp: %s", resp);
    if (sscanf(resp, "%10s %d,%d,\"%10[^\"]\",\"%10[^\"]\",%d", header, &n, &stat, lac, ci, &act) > 5)
    {
        CLOG_DBG("header: %s; n:%d; stat: %d; lac: %s; ci: %s; act:%d", header, n, stat, lac, ci, act);
        CLOG_NOTICE("%s", cellular_reg_state_2_str((register_state_t)stat));
        info->reg = (register_state_t)stat;
        if (act == 100)
        {
            info->cellid = strtoul(ci, NULL, 16);
            info->lac_nid.nid_sid.nid = (info->cellid >> 16) & 0xFFFF;
            info->cellid &= 0xFFFF;
            info->lac_nid.nid_sid.sid = strtoul(lac, NULL, 16);
            info->act = NETWORK_ACT_CDMA;
            CLOG_NOTICE("Cell info: bid: 0x%X; nid: 0x%X; sid: 0x%X", info->cellid, info->lac_nid.nid_sid.nid, info->lac_nid.nid_sid.sid);
        }
        else
        {
            info->cellid = strtoul(ci, NULL, 16);
            info->lac_nid.lac = strtoul(lac, NULL, 16);
            info->act = (network_act_t)act;
            CLOG_NOTICE("Cell info: cellid: 0x%X; LAC: 0x%X", info->cellid, info->lac_nid.lac);
        }
    }
    else
    {
        stat = 0;
    }
    if (REGISTER_STATE_REGISTERED_HOME == stat || REGISTER_STATE_REGISTERED_ROAM == stat)
    {
        return RT_TRUE;
    }
    else
    {
        memset(cmd, 0, sizeof(cmd));
        if (0 == idx)
        {
            snprintf(cmd, sizeof(cmd), "%s\r\n", "AT+CEREG=2;+CEREG?");
        }
        else if (1 == idx)
        {
            snprintf(cmd, sizeof(cmd), "%s\r\n", "AT+CGREG=2;+CGREG?");
        }
        else if (2 == idx)
        {
            snprintf(cmd, sizeof(cmd), "%s\r\n", "AT+CREG=2;+CREG?");
        }
        else
        {

        }
        if (strlen(cmd))
        {
            at_send_receive(c, cmd, "OK", 1000);
            idx++;
            goto parse_resp;
        }
    }
    return RT_FALSE;
}

/**
 * @brief query attach state
 *
 * @param c pointer to AT client
 * @param resp
 * @param usr_ctx
 * @return int
 *          0: failed
 *          !0: success
 */
int cellular_comm_query_attach(at_client_t c, const char *resp, void *usr_ctx)
{
    /**
     * +CGATT: 1
     *
     * OK
     *
     */
    char header[12] = {0};
    int stat = 0;
    RT_ASSERT(c);
    RT_ASSERT(resp);
    CHECK_HEADER_AND_RETURN_IF_NULL(resp, "+CGATT:");
    if (sscanf(resp, "%s %d", header, &stat) >= 2)
    {
        CLOG_DBG("header: %s; stat: %d; ", header, stat);
        if (0 == stat)
        {
            //return at_send_receive(c, "AT+CGATT=1\r\n", "OK", 5000);
            return RT_FALSE;
        }
        return RT_TRUE;
    }

    return RT_FALSE;
}

/**
 * @brief query operator
 *
 * @param c pointer to AT client
 * @param resp
 * @param usr_ctx
 * @return int
 *          0: failed
 *          !0: success
 */
int cellular_comm_query_operator(at_client_t c, const char *resp, void *usr_ctx)
{
    char oper[16] = {0};
    int mode = 0, format = 0;
    RT_ASSERT(c);
    RT_ASSERT(resp);
    RT_ASSERT(usr_ctx);
    cell_access_info_t info = cellular_get_cell_access_info((cellular_device_t)usr_ctx);
    CHECK_HEADER_AND_RETURN_IF_NULL(resp, "+COPS:");

    if (sscanf(resp, "%*[^ ] %d,%d,\"%[^\",]", &mode, &format, oper) > 2)
    {
        if (2 == format)
        {
            info->mnc = atoi(&oper[3]);
            oper[3] = '\0';
            info->mcc = atoi(oper);
            CLOG_DBG("mcmnc: %d %02d", info->mcc, info->mnc);
        }
        else
        {
            CLOG_NOTICE("Registered to %s", oper);
            snprintf(info->operator_name, sizeof(info->operator_name),"%s", oper);
        }

        return RT_TRUE;
    }
    return RT_FALSE;
}

/**
 * @brief connect data
 *
 * @param c pointer to AT client
 * @param resp
 * @param usr_ctx
 * @return int
 *          0: failed
 *          !0: success
 */
int cellular_comm_data_connect(at_client_t c, const char *resp, void *usr_ctx)
{
    char at[128] = {0};
    RT_ASSERT(c);
    RT_ASSERT(usr_ctx);
    char *call_number = (char *)usr_ctx;
    snprintf(at, sizeof(at), "ATD%s", call_number);
    CLOG_NOTICE("Begian to data call, may block for 15s...");
    return at_send_receive(c, at, "CONNECT", 15000);
}

/**
 * @brief disconnect data
 *
 * @param c pointer to AT client
 * @param resp
 * @param usr_ctx
 * @return int
 *          0: failed
 *          !0: success
 */
int cellular_comm_data_disconnect(at_client_t c, const char *resp, void *usr_ctx)
{
    RT_ASSERT(c);

    for (int i = 0; i < 3; i++)
    {
        if (at_exe_without_resp(c, "AT\r\n", "OK", 500) && at_exe_without_resp(c, "ATH\r\n", "OK", 5000))
        {
            return RT_TRUE;
        }
        at_exe_without_resp(c, "+++", "OK", 2000);
    }

    return at_exe_repeat(c, "ATH\r\n", "OK", 5000, 3);
}

const char *cellular_reg_state_2_str(register_state_t state)
{
    state = state > REGISTER_STATE_STATE_MAX ? REGISTER_STATE_STATE_MAX : state;
    return reg_state_info[state];
}

const char *cellar_band_2_str(network_act_band_t band)
{
    static char band_name[32] = {0};
    if (CDMA_BAND_800 == band)
    {
        snprintf(band_name, sizeof(band_name), "%s", "CDMA 800M");
    }
    else if (EVDO_BAND_800 == band)
    {
        snprintf(band_name, sizeof(band_name), "%s", "EVDO 800M");
    }
    else if (band < 20000)
    {
        snprintf(band_name, sizeof(band_name), "GSM %dM", band);
    }
    else if (TDSCDMA_BAND_34 == band)
    {
        snprintf(band_name, sizeof(band_name), "%s", "TD-SCDMA BandA");
    }
    else if (TDSCDMA_BAND_39 == band)
    {
        snprintf(band_name, sizeof(band_name), "%s", "TD-SCDMA BandF");
    }
    else if (band < 40000)
    {
        snprintf(band_name, sizeof(band_name), "WCDMA %dM", band % 3000);
    }
    else if (band < 50000)
    {
        snprintf(band_name, sizeof(band_name), "LTE Band%d", band % 4000);
    }
    else
    {
        snprintf(band_name, sizeof(band_name), "%s", "Unknown");
    }
    return band_name;
}

network_act_band_t cellular_arfcn_2_band(const char *act, int arfcn)
{
    network_act_band_t band = UNKNOWN_BAND;

    if (!strcasecmp(act, "GSM"))
    {
        if ((arfcn >= 975 && arfcn <= 1023) || (arfcn <= 124))
        {
            band = GSM_BAND_900;
        }
        else if (arfcn >= 512 && arfcn <= 885)
        {
            band = GSM_BAND_1800;
        }
        else if (arfcn >= 128 && arfcn <= 251)
        {
            band = GSM_BAND_850;
        }
        else
        {
        }
    }
    else if (!strcasecmp(act, "WCDMA"))
    {
        if (arfcn >= 9612 && arfcn <= 9888)
        {
            /**WCDMA 频点号arfcn = 中心频率*5 refer TS25.101**/
            //rel_band = arfcn/5.0f;
            //syslog(LOG_DEBUG,"WCDMA Uplink band: %.2fMHz",rel_band);
            band = WCDMA_BAND_2100;
        }
        else if (arfcn >= 10562 && arfcn <= 10838)
        {
            /**WCDMA 频点号arfcn = 中心频率*5 refer TS25.101**/
            //rel_band = arfcn/5.0f;
            //syslog(LOG_DEBUG,"WCDMA Downlink band: %.2fMHz",rel_band);
            band = WCDMA_BAND_2100;
        }
        else if ((arfcn >= 9262 && arfcn <= 9538))
        {
            /**WCDMA 频点号arfcn = 中心频率*5 refer TS25.101**/
            //rel_band = arfcn/5.0f;
            //syslog(LOG_DEBUG,"WCDMA Uplink band: %.2fMHz",rel_band);
            band = WCDMA_BAND_1900;
        }
        else if (arfcn >= 12 && arfcn <= 287)
        {
            /**WCDMA 频点号arfcn = 5*(中心频率-1850.1MHz) refer TS25.101**/
            //rel_band = arfcn/5.0f + 1850.1f;
            //syslog(LOG_DEBUG,"WCDMA Uplink band: %.2fMHz",rel_band);
            band = WCDMA_BAND_1900;
        }
        else if (arfcn >= 9662 && arfcn <= 9938)
        {
            /**WCDMA 频点号arfcn = 中心频率*5 refer TS25.101**/
            //rel_band = arfcn/5.0f;
            //syslog(LOG_DEBUG,"WCDMA Downlink band: %.2fMHz",rel_band);
            band = WCDMA_BAND_1900;
        }
        else if (arfcn >= 412 && arfcn <= 687)
        {
            /**WCDMA 频点号arfcn = 5*(中心频率-1850.1MHz) refer TS25.101**/
            //rel_band = arfcn/5.0f + 1850.1f;
            //syslog(LOG_DEBUG,"WCDMA Downlink band: %.2fMHz",rel_band);
            band = WCDMA_BAND_1900;
        }
        else if (arfcn >= 4132 && arfcn <= 4233)
        {
            /**WCDMA 频点号arfcn = 中心频率*5 refer TS25.101**/
            //rel_band = arfcn/5.0f;
            //syslog(LOG_DEBUG,"WCDMA Uplink band: %.2fMHz",rel_band);
            band = WCDMA_BAND_850;
        }
        else if (arfcn >= 782 && arfcn <= 862)
        {
            /**WCDMA 频点号arfcn = 5*(中心频率-670.1MHz) refer TS25.101**/
            //rel_band = arfcn/5.0f + 670.1f;
            //syslog(LOG_DEBUG,"WCDMA Uplink band: %.2fMHz",rel_band);
            band = WCDMA_BAND_850;
        }
        else if (arfcn >= 4357 && arfcn <= 4458)
        {
            /**WCDMA 频点号arfcn = 中心频率*5 refer TS25.101**/
            //rel_band = arfcn/5.0f;
            //syslog(LOG_DEBUG,"WCDMA Downlink band: %.2fMHz",rel_band);
            band = WCDMA_BAND_850;
        }
        else if (arfcn >= 1007 && arfcn <= 1087)
        {
            /**WCDMA 频点号arfcn = 5*(中心频率-670.1MHz) refer TS25.101**/
            //rel_band = arfcn/5.0f + 670.1f;
            //syslog(LOG_DEBUG,"WCDMA Uplink band: %.2fMHz",rel_band);
            band = WCDMA_BAND_850;
        }
        else if ((arfcn >= 2712 && arfcn <= 2863))
        {
            /**WCDMA 频点号arfcn = 5*(中心频率 - 340MHz) refer TS25.101**/
            //rel_band = arfcn/5.0f + 340;
            band = WCDMA_BAND_900;
            //syslog(LOG_DEBUG,"WCDMA Uplink band: %.2fMHz",rel_band);
        }
        else if (arfcn >= 2937 && arfcn <= 3088)
        {
            /**WCDMA 频点号arfcn = 5*(中心频率 - 340MHz) refer TS25.101**/
            //rel_band = arfcn/5.0f + 340;
            band = WCDMA_BAND_900;
            //syslog(LOG_DEBUG,"WCDMA Downlink band: %.2fMHz",rel_band);
        }
    }
    else if (!strcasecmp(act, "TD-SCDMA"))
    {
        if (arfcn >= 9400 && arfcn <= 9600)
        {
            band = TDSCDMA_BAND_39;
        }
        else if (arfcn >= 10050 && arfcn <= 10125)
        {
            band = TDSCDMA_BAND_34;
        }
        else
        {

        }
    }
    else if (!strcasecmp(act, "LTE"))
    {
        /**根据3GPP规范3GPP TS 36.101: **/
        /**FDL = FDL_low + 0.1(NDL - NOffs-DL)**/
        /**FUL = FUL_low + 0.1(NUL - NOffs-UL)**/
        if (arfcn >= 37750 && arfcn <= 38249)
        {
            //rel_band = 2570 + 0.1f*(arfcn - 37750);
            band = LTE_BAND_38;
            //syslog(LOG_DEBUG,"TDD-LTE band: %.2fMHz",rel_band);
        }
        else if (arfcn >= 38250 && arfcn <= 38649)
        {
            //rel_band = 1880 + 0.1f*(arfcn - 38250);
            band = LTE_BAND_39;
            //syslog(LOG_DEBUG,"TDD-LTE band: %.2fMHz",rel_band);
        }
        else if (arfcn >= 38650 && arfcn <= 39649)
        {
            //rel_band = 2300 + 0.1f * (arfcn - 38650);
            band = LTE_BAND_40;
            //syslog(LOG_DEBUG,"TDD-LTE band: %.2fMHz",rel_band);
        }
        else if (arfcn >= 39650 && arfcn <= 41589)
        {
            band = LTE_BAND_41;
        }
        else if (arfcn <= 599)
        {
            //rel_band = 2110 + 0.1f*(arfcn - 0);
            band = LTE_BAND_1;
            //syslog(LOG_DEBUG,"FDD-LTE Downlink band: %.2fMHz",rel_band);
        }
        else if (arfcn >= 18000 && arfcn <= 18599)
        {
            //rel_band = 1920 + 0.1f*(arfcn - 18000);
            band = LTE_BAND_1;
            //syslog(LOG_DEBUG,"FDD-LTE Uplonk band: %.2fMHz",rel_band);
        }
        else if (((arfcn >= 600) && (arfcn <= 1199)) || ((arfcn >= 18600) && (arfcn <= 19199)))
        {
            band = LTE_BAND_2;
        }
        else if (arfcn >= 1200 && arfcn <= 1949)
        {
            //rel_band = 1805 + 0.1f * (arfcn - 1200);
            band = LTE_BAND_3;
            //syslog(LOG_DEBUG,"FDD-LTE Downlink band: %.2fMHz",rel_band);
        }
        else if (arfcn >= 19200 && arfcn <= 19949)
        {
            //rel_band = 1710 + 0.1f * (arfcn - 19200);
            band = LTE_BAND_3;
            //syslog(LOG_DEBUG,"FDD-LTE Uplink band: %.2fMHz",rel_band);
        }
        else if (((arfcn >= 1950) && (arfcn <= 2399)) || ((arfcn >= 19950) && (arfcn <= 20399)))
        {
            band = LTE_BAND_4;
        }
        else if ((arfcn >= 2400 && arfcn <= 2649) || (arfcn >= 20400 && arfcn <= 20649))
        {
            band = LTE_BAND_5;
        }
        else if (arfcn >= 3450 && arfcn <= 3799)
        {
            //rel_band = 925 + 0.1f * (arfcn - 3450);
            band = LTE_BAND_8;
            //syslog(LOG_DEBUG,"FDD-LTE Downlink band: %.2fMHz",rel_band);
        }
        else if (arfcn >= 21450 && arfcn <= 21799)
        {
            //rel_band = 880 + 0.1f * (arfcn - 21450);
            band = LTE_BAND_8;
            //syslog(LOG_DEBUG,"FDD-LTE Uplink band: %.2fMHz",rel_band);
        }
        else if ((arfcn >= 5010 && arfcn <= 5179) || (arfcn >= 23010 && arfcn <= 23179))
        {
            band = LTE_BAND_12;
        }
        else if ((arfcn >= 5180 && arfcn <= 5279) || (arfcn >= 23180 && arfcn <= 23279))
        {
            band = LTE_BAND_13;
        }
        else if ((arfcn >= 5859 && arfcn <= 5999) || (arfcn >= 23850 && arfcn <= 23999))
        {
            band = LTE_BAND_18;
        }
        else if ((arfcn >= 6000 && arfcn <= 6149) || (arfcn >= 24000 && arfcn <= 24149))
        {
            band = LTE_BAND_19;
        }
        else if ((arfcn >= 6150 && arfcn <= 6449) || (arfcn >= 24150 && arfcn <= 24449))
        {
            band = LTE_BAND_20;
        }
        else if ((arfcn >= 9210 && arfcn <= 9659) || (arfcn >= 27210 && arfcn <= 27659))
        {
            band = LTE_BAND_28;
        }
    }
    return band;
}


/* End of file****************************************************************/

